package test_activiti;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.json.JsonObjectConverter;
import org.activiti.engine.impl.persistence.entity.TaskEntity;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class MyTaskHandler implements TaskListener {

	  private Expression testJson;

	  public void notify(DelegateTask delegateTask) {
		  if(delegateTask.getEventName().equals(TaskListener.EVENTNAME_CREATE))
		  try{
			  System.out.println(testJson.getExpressionText());
			  JSONArray jo = JSONArray.fromObject(testJson.getExpressionText());

			  System.out.println("json 本地变量 task id =" +delegateTask.getId());
			  for(int i=0;i<jo.size();i++){
				  JSONObject it = jo.getJSONObject(i);
				  System.out.println("\t"+it.getString("key")+"="+it.getString("value"));
				  delegateTask.setVariableLocal(it.getString("key"), it.getString("value"));

			  }
			  System.out.println("json 本地变量 结束");

		  }catch(Throwable e){
			  e.printStackTrace();
		  }
	  }

}